/*
 * Copyright 1999-2018 Alibaba Group Holding Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.alibaba.nacos.example;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;

import java.util.Properties;
import java.util.concurrent.TimeUnit;

/**
 * client register.
 *
 * @author huangchangjin
 * @date 2023-05-23
 */
public class ClientRegisterDemo {
    public static void main(String[] args) throws NacosException {
        Properties properties = new Properties();
        properties.setProperty("serverAddr", "127.0.0.1:8848");
        properties.setProperty("namespace", "test_tenant");
        // 开启授权登入的情况下，需要输入账号密码
        properties.put("username", "nacos");
        properties.put("password", "nacos");
        NamingService naming = NamingFactory.createNamingService(properties);
        naming.registerInstance("nacos.test.3", "2.2.2.1", 9999);
        sleep(5);
    }

    private static void sleep(long num) {
        try {
            TimeUnit.MINUTES.sleep(num);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
